<?php
/**
 * Created by PhpStorm.
 * User: dt
 * Time: 11:44
 */
namespace common\base;
use backend\utils\CurlUtil;

/**
 * 服务基类
 * @package app\base
 */
class BService
{

    private static $_instances = array();

    /**
     * 单例初始化服务，所有服务都要集成该基类，并重写此方法
     * @param string $className
     * @return mixed
     */
    public static function getInstance($className = __CLASS__ )
    {
        if (empty(self::$_instances[$className])) {
            self::$_instances[$className] = new $className(null, null, []);
        }
        return self::$_instances[$className];
    }

    /**
     * 拼接返回信息数组
     * @param string $className
     * @return mixed
     */
    public static function getData($type,$message,$data=[])
    {
        $return = array (
            'type' => $type, //状态码
            'message' => $message, //提示信息
            'data' => $data, //提示信息
        );
        return $return;
    }

    /***
     *短信发送
     * @param $mobile $content $template $operat_name
     * @return array
     */
    public static function sendMessage($mobile,$template){
        $route = "https://help.aliyun.com/document_detail/55451.html?spm=5176.sms-account.109.2.66e3621Fl4wfD";//测试环境
        // 参数数组w
        $queryArr = array (
            'PhoneNumbers' => $mobile, //短信来源
            'SignName' => '口袋书',     //短信签名
            'TemplateCode' => $template, //   短信模板IDwwwww
        );
        $return = CurlUtil::getInstance()->post($route, $queryArr, false);
        return $return;
    }

}
